package com.cn.wanxi.servlet.back.company;

import com.cn.wanxi.dto.CompanyDto;
import com.cn.wanxi.service.ICompanyService;
import com.cn.wanxi.service.impl.CompanyServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/companyAdd")
public class CompanyAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

//        1.拿到页面的值
        String name = req.getParameter("name");
        String logo = req.getParameter("logo");
        String phone = req.getParameter("phone");
        String status = req.getParameter("status");
        String[] leixings = req.getParameterValues("leixing");
        String content = req.getParameter("content");
//        2.封装model
        CompanyDto companyDto = new CompanyDto();
        companyDto.setName(name);
        companyDto.setLogo(logo);
        companyDto.setPhone(phone);
        companyDto.setStatus(status);
        companyDto.setLeixings(leixings);
        companyDto.setContent(content);
//        3.调用服务逻辑层
        ICompanyService iCompanyService = new CompanyServiceImpl();
        iCompanyService.add(companyDto);
//        4.返回页面
        resp.sendRedirect("/back/companyAdd.jsp");//重定向
//        页面转发，带值传递
//        req.getRequestDispatcher("/back/companyAdd.jsp").forward(req,resp);

    }
}
